Description:
DIC detects invalid type casts that will result in a
System.InvalidCastException
being thrown at runtime. Such situations occur when a variable is checked to
be an instance of type A and then inside the same conditional
branch is casted to another type B which is not the same type
as A and is not a base type of A.
Incorrect:
object obj;
...
if (obj is string) {
if (((System.Text.StringBuilder) obj)[0] == '#') {
...
Correct:
object obj;
...
if (obj is string) {
if (((string) obj)[0] == '#') {
...